package com.fr.report.highlight;

import com.fr.base.FRContext;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.CellElement;
import com.fr.report.cellElement.Formula;
import com.fr.report.core.ScriptUtils;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.script.Calculator;
import com.fr.report.script.CurrentValueNameSpace;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ValueHighlightAction extends AbstractHighlightAction
{
  private Object obj;

  public ValueHighlightAction()
  {
  }

  public ValueHighlightAction(Object paramObject)
  {
    this.obj = paramObject;
  }

  public Object getValue()
  {
    return this.obj;
  }

  public void setValue(Object paramObject)
  {
    this.obj = paramObject;
  }

  public void action(CellElement paramCellElement, Calculator paramCalculator)
  {
    if (paramCellElement == null)
      return;
    if (this.obj instanceof Formula)
    {
      Object localObject1 = paramCellElement.getValue();
      if (localObject1 instanceof Formula)
        localObject1 = ((Formula)localObject1).getResult();
      CurrentValueNameSpace localCurrentValueNameSpace = new CurrentValueNameSpace(localObject1);
      paramCalculator.pushNameSpace(localCurrentValueNameSpace);
      Formula localFormula = (Formula)this.obj;
      Object localObject2 = ScriptUtils.executeFormula(paramCalculator, localFormula);
      if ((localFormula.isReserveInResult()) || (localFormula.isReserveOnWrite()))
        try
        {
          localFormula = (Formula)localFormula.clone();
          localFormula.setContent(paramCalculator.exStatement(paramCalculator.getCurrentColumnRow(), localFormula.getContent()));
          localFormula.setResult(localObject2);
          paramCellElement.setValue(localFormula);
        }
        catch (CloneNotSupportedException localCloneNotSupportedException)
        {
          FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
          paramCellElement.setValue(localObject2);
        }
      else
        paramCellElement.setValue(localObject2);
      paramCalculator.removeNameSpace(localCurrentValueNameSpace);
    }
    else
    {
      paramCellElement.setValue(this.obj);
    }
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if ("O".equals(str))
        setValue(ReportXMLUtils.readObject(paramXMLableReader));
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    ReportXMLUtils.writeObject(paramXMLPrintWriter, getValue());
  }
}